package cn.edu.scau.cmi.dengzhengyu.multiton;

import java.util.ArrayList;
import java.util.List;


public class Chairmans {
	private static List<Chairmans> ins = new ArrayList<>();
	private String name;

	
	private Chairmans(String name) {
		this.name = name;
	}
	public static Chairmans getInstance(String name) {
		
		if(name == ""){
			return ins.get((int)(Math.random()*10)%ins.size());
		}
		else if (ins.size() < 10 && !ins.contains(new Chairmans(name))) {
			ins.add(new Chairmans(name));
			return ins.get(ins.size() - 1);
		}
		else {

			return ins.get((int)(Math.random()*10)%ins.size());
		}
	}

	public String getName() {
		return this.name;
	}
	
	public String toString() {
		return this.name + super.toString();
	}
	
	
}
